package com.RedRiver.hospitalsystem.personal_service.common.util;


import com.RedRiver.hospitalsystem.personal_service.common.Personal_serviceResultCode;
import com.RedRiver.hospitalsystem.personal_service.common.exception.ScheduleException;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class SplitTimeIntoDate {


    public static Integer SplitDateTime(LocalDateTime date) {

        LocalDateTime time2 = LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),8,00,00);

        LocalDateTime time1 = LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),12,00,00);

        LocalDateTime time3 = LocalDateTime.of(date.getYear(),date.getMonthValue(),date.getDayOfMonth(),19,00,00);

        if (date.getHour()>=8&&date.getHour()<12) return 1;

        if (date.getHour()>=12&&date.getHour()<19) return 2;

        return 0;

    }


    public static String SplitDate(LocalDateTime date){

        System.out.println(date);

    if (date.getMonthValue()<10&&date.getMonthValue()>0&&date.getDayOfMonth()>0&&date.getDayOfMonth()<10)
                                        return date.getYear()+"-0"+date.getMonthValue()+"-0"+date.getDayOfMonth();

    if (date.getMonthValue()<10&&date.getMonthValue()>0&&date.getDayOfMonth()>=10&&date.getDayOfMonth()<=31)
                                        return date.getYear()+"-0"+date.getMonthValue()+"-"+date.getDayOfMonth();

    if (date.getMonthValue()>=10&&date.getDayOfMonth()>0&&date.getDayOfMonth()<10&&date.getMonthValue()<=12)
                                        return date.getYear()+"-"+date.getMonthValue()+"-0"+date.getDayOfMonth();

    if (date.getMonthValue()>=10&&date.getDayOfMonth()>=10&&date.getMonthValue()<=12&&date.getDayOfMonth()<=31)
                                        return date.getYear()+"-"+date.getMonthValue()+"-"+date.getDayOfMonth();

        throw new ScheduleException(Personal_serviceResultCode.LOCALDATETIME_ERROR);
    }

}
